package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.RecruitPlanItem;
import cn.wolfcode.crm.domain.Recruitplan;
import cn.wolfcode.crm.qo.PageResult;
import cn.wolfcode.crm.qo.QueryObject;
import cn.wolfcode.crm.service.IRecruitPlanItemService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("recruitPlanItem")
@Controller
public class RecruitPlanItemController {
    @Autowired
    private IRecruitPlanItemService recruitPlanItemService;

    @RequestMapping("query")
    @ResponseBody
    public PageResult query(QueryObject qo) {
        return recruitPlanItemService.query(qo);
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(RecruitPlanItem recruitPlanItem) {
        try {
            if (recruitPlanItem.getId() != null)
                recruitPlanItemService.updateByPrimaryKey(recruitPlanItem);
            else
                recruitPlanItemService.insert(recruitPlanItem);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("保存失败!");
        }
        return JSONResult.success("保存成功!");
    }

    @RequestMapping("selectAll")
    @ResponseBody
    public List<RecruitPlanItem> selectAll() {
        return recruitPlanItemService.selectAll();
    }

    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id) {
        try {
            recruitPlanItemService.deleteByPrimaryKey(id);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("删除失败!");
        }
        return JSONResult.success("删除成功!");
    }
}
